package com.qf;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.pojo.DtsRegion;
import com.qf.service.RegionService;
import com.qf.util.ResponseUtil;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

/**
 * @author sunyamei
 * @version V1.0
 * @Project javase2203
 * @Package com.qf.controller
 * @Description:
 * @Date 2022/7/28 14:24
 */
@CrossOrigin("*")
@RequestMapping("/region")
@RestController
public class RegionController {

    @Autowired
    private RegionService regionService;

    /**
     *
     * 分页查询
     * @param page
     * @param limit
     * @param name
     * @param code
     * @return
     */
    @RequestMapping("/list")
    public  Object regionPage(Integer page,Integer limit,String name, Integer code){

        //创建查询条件
        IPage<DtsRegion> iPage = regionService.queryRegionPage(page, limit, name, code);

        //查询总条数
        long total = iPage.getTotal();

        //查询总页数
        List<DtsRegion> list = iPage.getRecords();

        //封装
        HashMap<Object, Object> data = new HashMap<>();
        data.put("total",total );
        data.put("items", list);
        return ResponseUtil.ok(data);


        }
    }

